package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the listSensordata method with various inputs for correct outputs.
 * 
 * @author Alex Kan and Kelvin Green
 * @version 2.0
 */
public class TestWattDepotListSensordata {

  WattDepotCommand commandInstance;
  String[] commandArray;
  String userInput;

  /**
   * Test WattDepotListSensordata for 2 correct outputs and errors on 4 inputs.
   * 
   * Test (correct) sensordata SIM_WAIAU_7 timestamp 2009-11-15T02:00:00.000-10:00: powerGenerated:
   * 880
   * 
   * Test (correct) dailysensordata SIM_WAIAU_7 day 2009-11-15: OscarDataConverter
   * 
   * Test (error)sensordata SIM_WAIAU_11 timestamp 2009-11-15T02:00:00.000-10:00 1: Correct format
   * is sensordata {source} timestamp {timestamp}
   * 
   * Test (error) sensordata SIM_WAIAU_7 timestamp 2009-11-1502:00:00.000-10:00: Not a valid
   * timestamp.
   * 
   * Test (error) dailysensordata SIM_WAIAU day 2009-11-15 1: dailysensordata {source} day {day}
   * 
   * Test (error) dailysensordata SIM_WAIAU_7 day 2009/11-15: Day is not properly formatted.
   */
  @Test
  public void testListSensordata() {
    String CHECK_ERROR = "Check for error";
    WattDepotCommand.connect("http://server.wattdepot.org:8182/wattdepot/");
    commandInstance = new WattDepotListSensordataCommand();
    userInput = "sensordata SIM_WAIAU_7 timestamp 2009-11-15T02:00:00.000-10:00";
    commandArray = userInput.split(" ");
    assertTrue("Check for sensordata SIM_WAIAU_7", commandInstance.doCommand(commandArray)
        .contains("powerGenerated: 880"));

    commandInstance = new WattDepotListSensordataCommand();
    userInput = "sensordata SIM_WAIAU_11 timestamp 2009-11-15T02:00:00.000-10:00 1";
    commandArray = userInput.split(" ");
    assertTrue(CHECK_ERROR, commandInstance.doCommand(commandArray).contains(
        "Correct format is sensordata {source} timestamp {timestamp}"));

    commandInstance = new WattDepotListSensordataCommand();
    userInput = "sensordata SIM_WAIAU_7 timestamp 2009-11-1502:00:00.000-10:00";
    commandArray = userInput.split(" ");
    assertTrue(CHECK_ERROR, commandInstance.doCommand(commandArray).contains(
        "Not a valid timestamp."));

    commandInstance = new WattDepotListDailySensordataCommand();
    userInput = "dailysensordata SIM_WAIAU_7 day 2009-11-15";
    commandArray = userInput.split(" ");
    assertTrue("Check for dailysensordata SIM_WAIAU_7", commandInstance.doCommand(commandArray)
        .contains("OscarDataConverter"));

    commandInstance = new WattDepotListDailySensordataCommand();
    userInput = "dailysensordata SIM_WAIAU day 2009-11-15 1";
    commandArray = userInput.split(" ");
    assertTrue(CHECK_ERROR, commandInstance.doCommand(commandArray).contains(
        "dailysensordata {source} day {day}"));

    commandInstance = new WattDepotListDailySensordataCommand();
    userInput = "dailysensordata SIM_WAIAU_7 day 2009/11-15";
    commandArray = userInput.split(" ");
    assertTrue(CHECK_ERROR, commandInstance.doCommand(commandArray).contains(
        "Day is not properly formatted."));

  }

}
